
	<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>草莓系统登录</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="/static/css/oksub.css">
	<script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
	<style>
		.layui-upload-list img{
			height:100px;
			width:100px;
		}
	</style>
</head>
<body>
<div class="ok-body" id="denglu">
	<!--form表单-->
	<form class="layui-form layui-form-pane ok-form">

        <div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input"
					   lay-verify="required">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">密码</label>
			<div class="layui-input-block">
				<input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input"
				       lay-verify="required">
			</div>
		</div>
		
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="add">立即登录</button>
				<button type="reset" class="layui-btn layui-btn-primary" id="quzhuce">没账户去注册</button>
			</div>
		</div>
	</form>
</div>


<!-- 注册 -->
<div class="ok-body" id="zhuce" style="display: none;">
	<!--form表单-->
	<form class="layui-form layui-form-pane ok-form">

        <div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input"
					   lay-verify="required">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">密码</label>
			<div class="layui-input-block">
				<input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input"
				       lay-verify="required">
			</div>
		</div>
		
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-primary" lay-submit id="qudenglu">有账户去登录</button>
				<button lay-submit lay-filter="reg" class="layui-btn">立即注册</button>
			</div>
		</div>
	</form>
</div>


<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
	$("#quzhuce").click(function(){
		$("#zhuce").show(100);
		$("#denglu").hide(100);
	});

	$("#qudenglu").click(function(){
		$("#zhuce").hide(100);
		$("#denglu").show(100);
	});

</script>
<script>
	
	layui.use(["element", "form", "laydate", "okLayer", "okUtils"], function () {
		let form = layui.form;
		let laydate = layui.laydate;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;

		okLoading.close();

		//laydate.render({elem: "#birthday", type: "datetime"});

		form.verify({
			
		});

		form.on("submit(add)", function (data) {
			okUtils.ajax("http://stapi.shiliucrm.com/api/user/login", "post", data.field, true).done(function (response) {
				//console.log(response);
				if(response.code==1){
					okLayer.greenTickMsg("登录成功", function () {

						const Storage = {};
						Storage.get = function(name) {
							return localStorage.getItem(name);
						}

						Storage.set = function(name, val) {
							localStorage.setItem(name, val);
						}

						Storage.set("caomeiadmin_userinfo", response.data.token);
      					console.log(Storage.get("caomeiadmin_userinfo"));

						parent.layer.close(parent.layer.getFrameIndex(window.name));
					});
				}else{
					okLayer.redCrossMsg(response.msg, function () {
				        
				    })
				}
				
			}).fail(function (error) {
				console.log(error)
			});
			return false;
		});


		//注册
		form.on("submit(reg)", function (data) {
			okUtils.ajax("http://stapi.shiliucrm.com/api/user/reg", "post", data.field, true).done(function (response) {
				//console.log(response);
				if(response.code==1){
					okLayer.greenTickMsg("注册成功", function () {

						const Storage = {};
						Storage.get = function(name) {
							return localStorage.getItem(name);
						}

						Storage.set = function(name, val) {
							localStorage.setItem(name, val);
						}

						Storage.set("caomeiadmin_userinfo", response.data.token);
      					console.log(Storage.get("caomeiadmin_userinfo"));

						parent.layer.close(parent.layer.getFrameIndex(window.name));
					});
				}else{
					okLayer.redCrossMsg(response.msg, function () {
				        
				    })
				}
				
			}).fail(function (error) {
				console.log(error)
			});
			return false;
		});


	});
</script>

</body>
</html>
